<template>
  <list-layout
    :categories="categories"
    @changed="categoryChanged"
    :originalCategory="currentCategory"
    channel="uc">
    <div class="list-top-text">
      {{$t((currentCategory && currentCategory.text) || '账号信息')}}
    </div>
    <router-view></router-view>
  </list-layout>
</template>

<script>
import mixins from 'eis-admin-mixins';
// import store from 'eis-admin-passport/store';
import listLayout from '../../components/listLayout.vue';

export default {
  name: 'UCLayout',
  mixins: [mixins.ObjectDataMixin],
  components: {
    listLayout,
  },
  data() {
    return {
      currentCategory: {},
      categories: [
        {
          text: '账号信息',
          filter: {
            url: '/uc/info',
          },
        },
        {
          text: '标委会成员',
          filter: {
            url: '/uc/committee',
          },
        },
        // {
        //   text: 'SC42成员',
        //   filter: {
        //     url: '/uc/committee',
        //   },
        // },
        // {
        //   text: 'SC35成员',
        //   filter: {
        //     url: '/uc/sc35',
        //   },
        // },
        // {
        //   text: '修改账号信息',
        //   filter: {
        //     url: '/uc/edit',
        //   },
        // },
        {
          text: '修改密码',
          filter: {
            url: '/uc/recover',
          },
        },
        {
          text: '在线测试结果',
          filter: {
            url: '/uc/tests',
          },
        },
        {
          text: '行业检测结果',
          filter: {
            url: '/uc/evalresults',
          },
        },
        {
          text: '我的留言',
          filter: {
            url: '/uc/feedback',
          },
        },
        // {
        //   text: '我的通知',
        //   filter: {
        //     url: '/uc/notifications',
        //   },
        // },
      ],
    };
  },
  beforeCreate() {
    if (this.ctx.modules.passport
      && this.ctx.modules.passport.store.state.passport.user
      && this.ctx.modules.passport.store.state.passport.user.Name) {
      //
    } else {
      this.$router.replace(`/login?redirect=${this.$route.fullPath}`);
    }
  },
  created() {
    this.updateCategory();
  },
  watch: {
    $route() {
      this.updateCategory();
    },
  },
  methods: {
    updateCategory() {
      this.currentCategory = this.categories.find((cat) => cat.filter.url === this.$route.fullPath
        || this.$route.fullPath.startsWith(`${cat.filter.url}/`));
    },
    categoryChanged(f, c) {
      this.currentCategory = c;

      this.$router.push(f.url || '/uc');
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
